﻿Imports System.IO

Public Class Frm_Rech_Clients

    Private Sub Frm_Rech_Clients_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            Partager.frmMoule.Enabled = True
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
       
    End Sub

    Private Sub Frm_Rech_Clients_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        comb_matorido_elbaht.SelectedIndex = 0
        Frm_Recherche.focs = ""
    End Sub

    Private Sub txt_rech_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_rech.TextChanged
        Try
            List_tous.Items.Clear()
            Partager.list_recherch.Clear()
            If comb_matorido_elbaht.SelectedItem = "رقم البطاقة الوطنية" Then
                For Each av As Client In Partager.moi.List_client
                    If av.Cin.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Nom_ent}))

                    End If

                Next


            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم العائلي" Then

                For Each av As Client In Partager.moi.List_client
                    If av.Nom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Nom_ent}))
                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "الاسم الشخصي" Then

                For Each av As Client In Partager.moi.List_client
                    If av.Prenom.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Nom_ent}))
                    End If

                Next

            ElseIf comb_matorido_elbaht.SelectedItem = "اسم الشركة" Then

                For Each av As Client In Partager.moi.List_client
                    If av.Nom_ent.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Nom_ent}))
                    End If

                Next
            ElseIf comb_matorido_elbaht.SelectedItem = "اسم الممثل القانوني" Then

                For Each av As Client In Partager.moi.List_client
                    If av.Representant_legal.ToString.Contains(txt_rech.Text) Then
                        Partager.list_recherch.Add(av)
                        List_tous.Items.Add(New ListViewItem(New String() {av.Nom, av.Prenom, av.Nom_ent}))
                    End If

                Next
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
        If txt_rech.Text = "" Then
            List_tous.Items.Clear()
        End If
    End Sub

    Private Sub Btn_choisi_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_choisi.Click

        If List_tous.SelectedIndices.Count > 0 Then

            Dim avo As Client
            Dim j As Integer = 0
            Dim str As String = ""
            Try
                For Each i As Integer In List_tous.SelectedIndices
                    avo = Partager.list_recherch(i)
                    If Partager.type_rech_mowakil = "Frm_Ref" Then

                        If avo.Type = "ذاتي" Then
                            str = avo.Nom & "  " & avo.Prenom
                        ElseIf avo.Type = "معنوي" Then
                            str = avo.Nom_ent
                        End If

                        If Partager.frmMoule.Name = "Frm_Recherche" Then
                            Partager.remplirClient(Frm_Recherche.Comb_nom)
                        End If

                        For Each cmb As Control In Partager.frmMoule.Controls
                            If TypeOf cmb Is ComboBox Then
                                If cmb.Name = "Comb_nom" Then
                                    cmb.Text = str
                                    Exit For
                                End If
                            End If
                        Next
                    Else
                        For Each khib As Client In Partager.moi.List_client
                            If avo.Id = khib.Id Then
                                Frm_Clients.List_tous.Items(j).Focused = True
                                Frm_Clients.List_tous.Items(j).Selected = True
                            End If
                            j += 1
                        Next
                    End If
                Next
                Me.Close()
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
        Else
            MsgBox("اختر موكل من القائمة", MsgBoxStyle.Information, "خطأ في البحث")
        End If
    End Sub


    Private Sub comb_matorido_elbaht_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles comb_matorido_elbaht.SelectedIndexChanged
        txt_rech.Clear()
    End Sub

    Private Sub List_tous_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles List_tous.SelectedIndexChanged

    End Sub
End Class
